package cn.adviceclient.features.value.slider;


import cn.adviceclient.features.value.AbstractSetting;

public class NumberSetting<N extends Number> extends AbstractSetting<N> {
    protected N max;
    protected N min;
    protected N step;

    public NumberSetting(String name, String description, N value, N max, N min, N step) {
        super(name, description, value);
        this.max = max;
        this.min = min;
        this.step = step;
    }

    public NumberSetting(String name, String description, N value, N max, N min, N step, java.util.function.Supplier<Boolean> visible) {
        super(name, description, value, visible);
        this.max = max;
        this.min = min;
        this.step = step;
    }

    public N getMax() {
        return max;
    }

    public void setMax(N max) {
        this.max = max;
    }

    public N getMin() {
        return min;
    }

    public void setMin(N min) {
        this.min = min;
    }

    public N getStep() {
        return step;
    }

    public void setStep(N step) {
        this.step = step;
    }
    
    /**
     * Sets the value from a double, handling type conversion
     * @param value The double value to set
     */
    public void setValueFromDouble(double value) {
        if (this.value instanceof Integer) {
            setValue((N) Integer.valueOf((int) Math.round(value)));
        } else if (this.value instanceof Float) {
            setValue((N) Float.valueOf((float) value));
        } else if (this.value instanceof Double) {
            setValue((N) Double.valueOf(value));
        }
    }
}